package com.intelligencesoft.pss.entity.listeners;

import java.util.LinkedList;
import java.util.List;

import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

import com.intelligencesoft.pss.entity.BasePojo;

public class ModelListener {
	private static final List<ModelHandler> modelHandlers = new LinkedList<ModelHandler>();
	 public static void addModelHandler(ModelHandler modelHandler){
	        modelHandlers.add(modelHandler);
	    }
	    public static void removeModelHandler(ModelHandler modelHandler){
	        modelHandlers.remove(modelHandler);
	    }
	@PrePersist
	public void prePersist(BasePojo model){
		 for(ModelHandler modelHandler : modelHandlers){
	            modelHandler.prePersist(model);
	        }
	}
	@PreUpdate
	public void preUpdate(BasePojo model){
		 for(ModelHandler modelHandler : modelHandlers){
	            modelHandler.preUpdate(model);
	        }
	}
	

}
